<?php
namespace App\Http\Controllers\User;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\DB;
use App\Models\GoodsModel;

class ResearchLineController extends Controller{

    public function __construct()
    {
        $this->middleware('user_login');
    }

    /**
     * 研学线路
     */
    public function research_line(Request $request,GoodsModel $goodsModel){
        //\DB::enableQueryLog();

        $query = $goodsModel->select(['*']);
        if(!empty($request->input('country_id'))){
            $query->where('country_id',$request->input('country_id'));
        }

        if(!empty($request->input('line_id'))){
            $query->where('country_id',$request->input('line_id'));
        }

        if(!empty($request->input('city_id'))){
            $query->where('city_id',$request->input('city_id'));
        }

        if(!empty($request->input('keyword'))){
            //dd($request->input('keyword'));
            $query->where('title','like','%'.$request->input('keyword').'%');
        }

        $data = $query->paginate(5);
      //  dd(DB::getQueryLog());

        return returnMsg(0,'获取成功',$data);
    }

    //线路详情
    public function research_line_info(Request $request,GoodsModel $goodsModel){

        $query = $goodsModel->select(['*']);

        $data = $query->where('id',$request->input('goods_id'))->first();

        return returnMsg(0,'获取成功',$data);
    }

}